home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / fileutil.zip / CAT.C < prev    next >
Text File  |  1994-07-16  |  19KB  |  788 lines

  1. /* cat -- concatenate files and print on the standard output.
  2.    Copyright (C) 1988, 1990 Free Software Foundation, Inc.
  3.  
  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 1, or (at your option)
  7.    any later version.
  8.  
  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU General Public License
  15.    along with this program; if not, write to the Free Software
  16.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  17.  
  18. /* MS-DOS port (c) 1990 by Thorsten Ohl, ohl@gnu.ai.mit.edu
  19.    This port is also distributed under the terms of the
  20.    GNU General Public License as published by the
  21.    Free Software Foundation.
  22.  
  23.    Please note that this file is not identical to the
  24.    original GNU release, you should have received this
  25.    code as patch to the official release.
  26.  
  27.    Friday, 15 July 1994  Troy Rollo (troy@cbme.unsw.EDU.AU)
  28.  
  29.     - Moved definition of max macro to be dependent only on
  30.       previous definition of max.
  31.  
  32.  */
  33.  
  34. #ifdef MSDOS
  35. static char RCS_Id[] =
  36.   "$Header: e:/gnu/fileutil/RCS/cat.c 1.4.0.2 90/09/19 11:17:40 tho Exp $";
  37.  
  38. static char Program_Id[] = "cat";
  39. static char RCS_Revision[] = "$Revision: 1.4.0.2 $";
  40.  
  41. #define VERSION \
  42.   "GNU %s, Version %.*s (compiled %s %s for MS-DOS)\n", Program_Id, \
  43.   (sizeof RCS_Revision - 14), (RCS_Revision + 11), __DATE__, __TIME__
  44.  
  45. #define COPYING \
  46.   "This is free software, distributed under the terms of the\n" \
  47.   "GNU General Public License.  For details, see the file COPYING.\n"
  48. #endif /* MSDOS */
  49.  
  50. /* Differences from the Unix cat:
  51.    * Always unbuffered, -u is ignored.
  52.    * 100 times faster with -v -u.
  53.    * 20 times faster with -v.
  54.  
  55.    By tege@sics.se, Torbjorn Granlund, advised by rms, Richard Stallman. */
  56.  
  57. #include <stdio.h>
  58. #include <getopt.h>
  59. #include <errno.h>
  60. #include <sys/types.h>
  61. #ifndef _POSIX_SOURCE
  62. #ifndef MSDOS
  63. #include <sys/ioctl.h>
  64. #endif
  65. #endif
  66. #include "system.h"
  67.  
  68. #ifdef STDC_HEADERS
  69. #include <stdlib.h>
  70. #else
  71. char *malloc ();
  72. void free ();
  73.  
  74. extern int errno;
  75. #endif
  76.  
  77. #ifdef MSDOS
  78.  
  79. #include <string.h>
  80. #include <fcntl.h>
  81. #include <malloc.h>
  82. #include <io.h>
  83.  
  84. extern void main (int, char **);
  85. extern void error (int status, int errnum, char *message, ...);
  86. extern void usage (char *);
  87. extern void simple_cat (unsigned char *, int);
  88. extern void cat (unsigned char *, int, unsigned char *,\
  89.          int, int, int, int, int, int, int);
  90. extern void next_line_num (void);
  91. extern char *copystring (char *, char *);
  92.  
  93. #else /* not MSDOS */
  94.  
  95.  
  96. char *copystring ();
  97. void cat ();
  98. void error ();
  99. void next_line_num ();
  100. void simple_cat ();
  101.  
  102. #endif /* not MSDOS */
  103.  
  104. #ifndef max
  105. #define max(h,i) ((h) > (i) ? (h) : (i))
  106. #endif
  107.  
  108. typedef unsigned char uchar;
  109.  
  110. /* Name under which this program was invoked.  */
  111. char *program_name;
  112.  
  113. /* Name of input file.  May be "-".  */
  114. char *infile;
  115.  
  116. /* Descriptor on which input file is open.  */
  117. int input_desc;
  118.  
  119. /* Descriptor on which output file is open.  Always is 1.  */
  120. int output_desc;
  121.  
  122. /* Buffer for line numbers.  */
  123. char line_buf[13] =
  124. {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '0', '\t', '\0'};
  125.  
  126. /* Position in `line_buf' where printing starts.  This will not change
  127.    unless the number of lines are more than 999999.  */
  128. char *line_num_print = line_buf + 5;
  129.  
  130. /* Position of the first digit in `line_buf'.  */
  131. char *line_num_start = line_buf + 10;
  132.  
  133. /* Position of the last digit in `line_buf'.  */
  134. char *line_num_end = line_buf + 10;
  135.  
  136. /* Preserves the `cat' function's local `newlines' between invocations.  */
  137. int newlines2 = 0;
  138.  
  139. /* Count of non-fatal error conditions.  */
  140. int exit_stat = 0;
  141.  
  142. void
  143. usage (reason)
  144.      char *reason;
  145. {
  146.   if (reason != NULL)
  147.     fprintf (stderr, "%s: %s\n", program_name, reason);
  148.  
  149. #ifdef MSDOS
  150.   fprintf (stderr, "\
  151. Usage: %s [-benstuvABET] [+number] [+number-nonblank] [+squeeze-blank]\n\
  152.        [+show-nonprinting] [+show-ends] [+show-tabs] [+show-all] [+binary]\n\
  153.        [+copying] [+version] [file...]\n", program_name);
  154. #else /* not MSDOS */
  155.   fprintf (stderr, "\
  156. Usage: %s [-benstuvAET] [+number] [+number-nonblank] [+squeeze-blank]\n\
  157.        [+show-nonprinting] [+show-ends] [+show-tabs] [+show-all] [file...]\n",
  158.        program_name);
  159. #endif /* not MSDOS */
  160.  
  161.   exit (2);
  162. }
  163.  
  164.  
  165. void
  166. main (argc, argv)
  167.      int argc;
  168.      char *argv[];
  169. {
  170.   /* Optimal size of i/o operations of output.  */
  171.   int outsize;
  172.  
  173.   /* Optimal size of i/o operations of input.  */
  174.   int insize;
  175.  
  176.   /* Pointer to the input buffer.  */
  177.   uchar *inbuf;
  178.  
  179.   /* Pointer to the output buffer.  */
  180.   uchar *outbuf;
  181.  
  182.   int c;
  183.  
  184.   /* Index in argv to processed argument.  */
  185.   int argind;
  186.  
  187.   /* Device number of the output (file or whatever).  */
  188.   int out_dev;
  189.  
  190.   /* I-node number of the output.  */
  191.   int out_ino;
  192.  
  193.   /* Nonzero if the output file should not be the same as any input file. */
  194.   int check_redirection = 1;
  195.  
  196.   struct stat stat_buf;
  197.  
  198.   /* Variables that are set according to the specified options.  */
  199.   int numbers = 0;
  200.   int numbers_at_empty_lines = 1;
  201.   int squeeze_empty_lines = 0;
  202.   int mark_line_ends = 0;
  203.   int quote = 0;
  204.   int output_tabs = 1;
  205.   int options = 0;
  206.   int longind;
  207. #ifdef MSDOS
  208.   int binary = 0;
  209. #endif
  210.  
  211.   static struct option long_options[] =
  212.   {
  213. #ifdef MSDOS
  214.     {"binary", 0, NULL, 'B'},
  215.     {"copying", 0, NULL, 30},
  216.     {"version", 0, NULL, 31},
  217. #endif
  218.     {"number-nonblank", 0, NULL, 'b'},
  219.     {"number", 0, NULL, 'n'},
  220.     {"squeeze-blank", 0, NULL, 's'},
  221.     {"show-nonprinting", 0, NULL, 'v'},
  222.     {"show-ends", 0, NULL, 'E'},
  223.     {"show-tabs", 0, NULL, 'T'},
  224.     {"show-all", 0, NULL, 'A'},
  225.     {NULL, 0, NULL, 0}
  226.   };
  227.  
  228.   program_name = argv[0];
  229.  
  230.   /* Parse command line options.  */
  231.  
  232. #ifdef MSDOS
  233.   while ((c = getopt_long (argc, argv, "benstuvABET", long_options, &longind))
  234. #else
  235.   while ((c = getopt_long (argc, argv, "benstuvAET", long_options, &longind))
  236. #endif
  237.      != EOF)
  238.     {
  239.       options++;
  240.       switch (c)
  241.     {
  242.     case 'b':
  243.       numbers = 1;
  244.       numbers_at_empty_lines = 0;
  245.       break;
  246.  
  247.     case 'e':
  248.       mark_line_ends = 1;
  249.       quote = 1;
  250.       break;
  251.  
  252.     case 'n':
  253.       numbers = 1;
  254.       break;
  255.  
  256.     case 's':
  257.       squeeze_empty_lines = 1;
  258.       break;
  259.  
  260.     case 't':
  261.       output_tabs = 0;
  262.       quote = 1;
  263.       break;
  264.  
  265.     case 'u':
  266.       /* We provide the -u feature unconditionally.  */
  267.       options--;
  268.       break;
  269.  
  270.     case 'v':
  271.       quote = 1;
  272.       break;
  273.  
  274.     case 'A':
  275.       quote = 1;
  276.       mark_line_ends = 1;
  277.       output_tabs = 0;
  278.       break;
  279.  
  280. #ifdef MSDOS
  281.     case 'B':
  282.       binary++;
  283.       options--;    /* stdout will be binary iff no other option!  */
  284.       break;
  285.  
  286.     case 30:
  287.       fprintf (stderr, COPYING);
  288.       exit (0);
  289.       break;
  290.  
  291.     case 31:
  292.       fprintf (stderr, VERSION);
  293.       exit (0);
  294.       break;
  295. #endif
  296.  
  297.     case 'E':
  298.       mark_line_ends = 1;
  299.       break;
  300.  
  301.     case 'T':
  302.       output_tabs = 0;
  303.       break;
  304.  
  305.     default:
  306.       usage ((char *) 0);
  307.     }
  308.     }
  309.  
  310.   output_desc = fileno (stdout);
  311.  
  312.   /* Get device, i-node number, and optimal blocksize of output.  */
  313.  
  314.   if (fstat (output_desc, &stat_buf) < 0)
  315.     error (1, errno, "standard output");
  316.  
  317.   outsize = ST_BLKSIZE (stat_buf);
  318.   switch (stat_buf.st_mode & S_IFMT)
  319.     {
  320.       /* Input file can be output file for non-regular files.
  321.      fstat on pipes returns S_IFSOCK on some systems, S_IFIFO
  322.      on others, so the checking should not be done for those types,
  323.      and to allow things like cat < /dev/tty > /dev/tty, checking
  324.      is not done for device files either. */
  325.     case S_IFREG:
  326.       out_dev = stat_buf.st_dev;
  327.       out_ino = stat_buf.st_ino;
  328.       break;
  329.     default:
  330.       check_redirection = 0;
  331.       break;
  332.     }
  333.  
  334.   /* Check if any of the input files are the same as the output file.  */
  335.  
  336.   /* Main loop.  */
  337.  
  338.   infile = "-";
  339.   argind = optind;
  340.  
  341.   do
  342.     {
  343.       if (argind < argc)
  344.     infile = argv[argind];
  345.  
  346.       if (infile[0] == '-' && infile[1] == 0)
  347.     input_desc = fileno (stdin);
  348.       else
  349.     {
  350.       input_desc = open (infile, O_RDONLY);
  351.       if (input_desc < 0)
  352.         {
  353.           error (0, errno, "%s", infile);
  354.           exit_stat = 1;
  355.           continue;
  356.         }
  357.     }
  358.  
  359. #ifdef MSDOS
  360.       if (binary)
  361.     {
  362.       setmode (input_desc, O_BINARY);
  363.  
  364.       /* We will not set the output to binary mode if we have
  365.          another (verbose) option active.  */
  366.       if (options == 0)
  367.         setmode (output_desc, O_BINARY);
  368.     }
  369. #endif
  370.  
  371.       if (fstat (input_desc, &stat_buf) < 0)
  372.     {
  373.       error (0, errno, "%s", infile);
  374.       close (input_desc);
  375.       exit_stat = 1;
  376.       continue;
  377.     }
  378.       insize = ST_BLKSIZE (stat_buf);
  379.  
  380.       /* Compare the device and i-node numbers of this input file with
  381.      the corresponding values of the (output file associated with)
  382.      stdout, and skip this input file if they coincide.  Input
  383.      files cannot be redirected to themselves.  */
  384.  
  385.       if (check_redirection
  386.       && stat_buf.st_dev == out_dev && stat_buf.st_ino == out_ino)
  387.     {
  388.       error (0, 0, "%s: input file is output file", infile);
  389.       exit_stat = 1;
  390.       continue;
  391.     }
  392.  
  393.       /* Select which version of `cat' to use. If any options (more than -u)
  394.      were specified, use `cat', otherwise use `simple_cat'.  */
  395.  
  396.       if (options == 0)
  397.     {
  398.       insize = max (insize, outsize);
  399.       inbuf = (uchar *) malloc (insize);
  400.       if (inbuf == NULL)
  401.         error (1, 0, "virtual memory exhausted");
  402.  
  403.       simple_cat (inbuf, insize);
  404.     }
  405.       else
  406.     {
  407. #ifdef MSDOS            /* the user wants it slow, he can get it! */
  408.       insize = outsize = 0x1000;
  409. #endif
  410.       inbuf = (uchar *) malloc (insize + 1);
  411.       if (inbuf == NULL)
  412.         error (1, 0, "virtual memory exhausted");
  413.  
  414.       /* Why are (OUTSIZE  - 1 + INSIZE * 4 + 13) bytes allocated for
  415.          the output buffer?
  416.  
  417.          A test whether output needs to be written is done when the input
  418.          buffer empties or when a newline appears in the input.  After
  419.          output is written, at most (OUTSIZE - 1) bytes will remain in the
  420.          buffer.  Now INSIZE bytes of input is read.  Each input character
  421.          may grow by a factor of 4 (by the prepending of M-^).  If all
  422.          characters do, and no newlines appear in this block of input, we
  423.          will have at most (OUTSIZE - 1 + INSIZE) bytes in the buffer.  If
  424.          the last character in the preceeding block of input was a
  425.          newline, a line number may be written (according to the given
  426.          options) as the first thing in the output buffer. (Done after the
  427.          new input is read, but before processing of the input begins.)  A
  428.          line number requires seldom more than 13 positions.  */
  429.  
  430.       outbuf = (uchar *) malloc (outsize - 1 + insize * 4 + 13);
  431.       if (outbuf == NULL)
  432.         error (1, 0, "virtual memory exhausted");
  433.  
  434.       cat (inbuf, insize, outbuf, outsize, quote,
  435.            output_tabs, numbers, numbers_at_empty_lines, mark_line_ends,
  436.            squeeze_empty_lines);
  437.  
  438.       free (outbuf);
  439.     }
  440.  
  441.       free (inbuf);
  442.       if (input_desc)
  443.     close (input_desc);
  444.     }
  445.   while (++argind < argc);
  446.  
  447.   exit (exit_stat);
  448. }
  449.  
  450. /* Plain cat.  Copies the file behind `input_desc' to the file behind
  451.    `output_desc'.  */
  452.  
  453. void
  454. simple_cat (buf, bufsize)
  455.      /* Pointer to the buffer, used by reads and writes.  */
  456.      uchar *buf;
  457.  
  458.      /* Number of characters preferably read or written by each read and write
  459.         call.  */
  460.      int bufsize;
  461. {
  462.   /* Actual number of characters read, and therefore written.  */
  463.   int n_read;
  464.  
  465.   /* Loop until the end of the file.  */
  466.  
  467.   for (;;)
  468.     {
  469.       /* Read a block of input.  */
  470.  
  471.       n_read = read (input_desc, buf, bufsize);
  472.       if (n_read < 0)
  473.     {
  474.       error (0, errno, "%s", infile);
  475.       exit_stat = 1;
  476.       return;
  477.     }
  478.  
  479.       /* End of this file?  */
  480.  
  481.       if (n_read == 0)
  482.     break;
  483.  
  484.       /* Write this block out.  */
  485.  
  486.       if (write (output_desc, buf, n_read) != n_read)
  487.     error (1, errno, "write error");
  488.     }
  489. }
  490.  
  491. /* Cat the file behind INPUT_DESC to the file behind OUTPUT_DESC.
  492.    Called if any option more than -u was specified.
  493.  
  494.    A newline character is always put at the end of the buffer, to make
  495.    an explicit test for buffer end unnecessary.  */
  496.  
  497. void
  498. cat (inbuf, insize, outbuf, outsize, quote,
  499.      output_tabs, numbers, numbers_at_empty_lines,
  500.      mark_line_ends, squeeze_empty_lines)
  501.  
  502.      /* Pointer to the beginning of the input buffer.  */
  503.      uchar *inbuf;
  504.  
  505.      /* Number of characters read in each read call.  */
  506.      int insize;
  507.  
  508.      /* Pointer to the beginning of the output buffer.  */
  509.      uchar *outbuf;
  510.  
  511.      /* Number of characters written by each write call.  */
  512.      int outsize;
  513.  
  514.      /* Variables that have values according to the specified options.  */
  515.      int quote;
  516.      int output_tabs;
  517.      int numbers;
  518.      int numbers_at_empty_lines;
  519.      int mark_line_ends;
  520.      int squeeze_empty_lines;
  521. {
  522.   /* Last character read from the input buffer.  */
  523.   uchar ch;
  524.  
  525.   /* Pointer to the next character in the input buffer.  */
  526.   uchar *bpin;
  527.  
  528.   /* Pointer to the first non-valid byte in the input buffer, i.e. the
  529.      current end of the buffer.  */
  530.   uchar *eob;
  531.  
  532.   /* Pointer to the position where the next character shall be written.  */
  533.   uchar *bpout;
  534.  
  535.   /* Number of characters read by the last read call.  */
  536.   int n_read;
  537.  
  538.   /* Determines how many consequtive newlines there have been in the
  539.      input.  0 newlines makes NEWLINES -1, 1 newline makes NEWLINES 1,
  540.      etc.  Initially 0 to indicate that we are at the beginning of a
  541.      new line.  The "state" of the procedure is determined by
  542.      NEWLINES.  */
  543.   int newlines = newlines2;
  544.  
  545. #ifdef FIONREAD
  546.   /* If nonzero, use the FIONREAD ioctl, as an optimization.
  547.      (On Ultrix, it is not supported on NFS filesystems.)  */
  548.   int use_fionread = 1;
  549. #endif
  550.  
  551.   /* The inbuf pointers are initialized so that BPIN > EOB, and thereby input
  552.      is read immediately.  */
  553.  
  554.   eob = inbuf;
  555.   bpin = eob + 1;
  556.  
  557.   bpout = outbuf;
  558.  
  559.   for (;;)
  560.     {
  561.       do
  562.     {
  563.       /* Write if there are at least OUTSIZE bytes in OUTBUF.  */
  564.  
  565.       if (bpout - outbuf >= outsize)
  566.         {
  567.           uchar *wp = outbuf;
  568.           do
  569.         {
  570.           if (write (output_desc, wp, outsize) != outsize)
  571.             error (1, errno, "write error");
  572.           wp += outsize;
  573.         }
  574.           while (bpout - wp >= outsize);
  575.  
  576.           /* Move the remaining bytes to the beginning of the
  577.          buffer.  */
  578.  
  579.           bcopy (wp, outbuf, bpout - wp);
  580.           bpout = outbuf + (bpout - wp);
  581.         }
  582.  
  583.       /* Is INBUF empty?  */
  584.  
  585.       if (bpin > eob)
  586.         {
  587. #ifdef FIONREAD
  588.           int n_to_read = 0;
  589.  
  590.           /* Is there any input to read immediately?
  591.          If not, we are about to wait,
  592.          so write all buffered output before waiting.  */
  593.  
  594.           if (use_fionread
  595.           && ioctl (input_desc, FIONREAD, &n_to_read) < 0)
  596.         {
  597.           if (errno == EOPNOTSUPP)
  598.             use_fionread = 0;
  599.           else
  600.             {
  601.               error (0, errno, "cannot do ioctl on `%s'", infile);
  602.               exit_stat = 1;
  603.               newlines2 = newlines;
  604.               return;
  605.             }
  606.         }
  607.           if (n_to_read == 0)
  608. #endif
  609.         {
  610.           int n_write = bpout - outbuf;
  611.  
  612.           if (write (output_desc, outbuf, n_write) != n_write)
  613.             error (1, errno, "write error");
  614.           bpout = outbuf;
  615.         }
  616.  
  617.           /* Read more input into INBUF.  */
  618.  
  619.           n_read = read (input_desc, inbuf, insize);
  620.           if (n_read < 0)
  621.         {
  622.           error (0, errno, "%s", infile);
  623.           exit_stat = 1;
  624.           newlines2 = newlines;
  625.           return;
  626.         }
  627.           if (n_read == 0)
  628.         {
  629.           newlines2 = newlines;
  630.           return;
  631.         }
  632.  
  633.           /* Update the pointers and insert a sentinel at the buffer
  634.          end.  */
  635.  
  636.           bpin = inbuf;
  637.           eob = bpin + n_read;
  638.           *eob = '\n';
  639.         }
  640.       else
  641.         {
  642.           /* It was a real (not a sentinel) newline.  */
  643.  
  644.           /* Was the last line empty?
  645.          (i.e. have two or more consecutive newlines been read?)  */
  646.  
  647.           if (++newlines > 0)
  648.         {
  649.           /* Are multiple adjacent empty lines to be substituted by
  650.              single ditto (-s), and this was the second empty line?  */
  651.  
  652.           if (squeeze_empty_lines && newlines >= 2)
  653.             {
  654.               ch = *bpin++;
  655.               continue;
  656.             }
  657.  
  658.           /* Are line numbers to be written at empty lines (-n)?  */
  659.  
  660.           if (numbers && numbers_at_empty_lines)
  661.             {
  662.               next_line_num ();
  663.               bpout = (uchar *) copystring (bpout, line_num_print);
  664.             }
  665.         }
  666.  
  667.           /* Output a currency symbol if requested (-e).  */
  668.  
  669.           if (mark_line_ends)
  670.         *bpout++ = '$';
  671.  
  672.           /* Output the newline.  */
  673.  
  674.           *bpout++ = '\n';
  675.         }
  676.       ch = *bpin++;
  677.     }
  678.       while (ch == '\n');
  679.  
  680.       /* Are we at the beginning of a line, and line numbers are requested?  */
  681.  
  682.       if (newlines >= 0 && numbers)
  683.     {
  684.       next_line_num ();
  685.       bpout = (uchar *) copystring (bpout, line_num_print);
  686.     }
  687.  
  688.       /* Here CH cannot contain a newline character.  */
  689.  
  690.       /* The loops below continue until a newline character is found,
  691.      which means that the buffer is empty or that a proper newline
  692.      has been found.  */
  693.  
  694.       /* If quoting, i.e. at least one of -v, -e, or -t specified,
  695.      scan for chars that need conversion.  */
  696.       if (quote)
  697.     for (;;)
  698.       {
  699.         if (ch >= 32)
  700.           {
  701.         if (ch < 127)
  702.           *bpout++ = ch;
  703.         else if (ch == 127)
  704.           *bpout++ = '^',
  705.             *bpout++ = '?';
  706.         else
  707.           {
  708.             *bpout++ = 'M',
  709.               *bpout++ = '-';
  710.             if (ch >= 128 + 32)
  711.               if (ch < 128 + 127)
  712.             *bpout++ = ch - 128;
  713.               else
  714.             *bpout++ = '^',
  715.               *bpout++ = '?';
  716.             else
  717.               *bpout++ = '^',
  718.             *bpout++ = ch - 128 + 64;
  719.           }
  720.           }
  721.         else if (ch == '\t' && output_tabs)
  722.           *bpout++ = '\t';
  723.         else if (ch == '\n')
  724.           {
  725.         newlines = -1;
  726.         break;
  727.           }
  728.         else
  729.           *bpout++ = '^',
  730.         *bpout++ = ch + 64;
  731.  
  732.         ch = *bpin++;
  733.       }
  734.       else
  735.     /* Not quoting, neither of -v, -e, or -t specified.  */
  736.     for (;;)
  737.       {
  738.         if (ch == '\t' && !output_tabs)
  739.           *bpout++ = '^',
  740.         *bpout++ = ch + 64;
  741.         else if (ch != '\n')
  742.           *bpout++ = ch;
  743.         else
  744.           {
  745.         newlines = -1;
  746.         break;
  747.           }
  748.  
  749.         ch = *bpin++;
  750.       }
  751.     }
  752. }
  753.  
  754. /* Compute the next line number.  */
  755.  
  756. void
  757. next_line_num ()
  758. {
  759.   char *endp = line_num_end;
  760.   do
  761.     {
  762.       if ((*endp)++ < '9')
  763.     return;
  764.       *endp-- = '0';
  765.     }
  766.   while (endp >= line_num_start);
  767.   *--line_num_start = '1';
  768.   if (line_num_start < line_num_print)
  769.     line_num_print--;
  770. }
  771.  
  772. /* A less stupid strcpy.  Returns a pointer to the end of the destination
  773.    string, instead of to the beginning.  Doesn't null-terminate the
  774.    destination.  */
  775.  
  776. char *
  777. copystring (dst, src)
  778.      char *dst;
  779.      char *src;
  780. {
  781.   char c;
  782.  
  783.   while (c = *src++)
  784.     *dst++ = c;
  785.  
  786.   return dst;
  787. }
  788.